local joy__sanlian = fk.CreateSkill {

  name = "joy__sanlian",

  tags = {  },

}



joy__sanlian:addEffect("active", {
  name = "joy__sanlian",
  anim_type = "drawcard",
  card_num = 3,
  target_num = 0,
  card_filter = function(self, player, to_select, selected)
    return #selected < 3
    and table.contains(player.player_cards[Player.Hand], to_select)
    and not player:prohibitDiscard(Fk:getCardById(to_select))
    and table.every(selected, function (id)
      return Fk:getCardById(id).type == Fk:getCardById(to_select).type
    end)
  end,
  can_use = function(self, player)
    return player:getHandcardNum() > 2
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local same = table.every(effect.cards, function (id)
      return Fk:getCardById(id).trueName == Fk:getCardById(effect.cards[1]).trueName
    end)
    room:throwCard(effect.cards, joy__sanlian.name, player, player)
    if not player.dead then
      player:drawCards(player:getLostHp(), joy__sanlian.name)
    end
    for _, p in ipairs(room:getAlivePlayers()) do
      if not p.dead then
        room:damage { from = player, to = p, damage = 1, skillName = joy__sanlian.name }
      end
    end
    if not player.dead and same then
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if player.dead then break end
        if not p:isNude() then
          local id = room:askForCardChosen(player, p, "he", joy__sanlian.name)
          room:throwCard({id}, joy__sanlian.name, p, player)
        end
      end
    end
  end,
})

return joy__sanlian